<?php

namespace App\Http\Controllers\Member;

use App\Http\Controllers\Core\HomeController as Home;
use App\Models\Job;
use App\Models\JobResumeAccess;
use App\Models\Member;
use Illuminate\Http\Request;

class InterviewController extends Home
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 面试详情
     * @param Request $request
     */
    public function info(Request $request)
    {
        if (!$this->isLogin()) {
            echo $this->retJson(1, '失败', '');
            exit;
        }
        //获取公司信息 职位信息 联系人 联系电话
        $id = $request->get('id');
        $access = JobResumeAccess::find($id);
        if (!$access) {
            echo $this->retJson(1, '失败', '');
            exit;
        }
        //获取工作信息
        $job = Job::select('company_cn', 'jobs_name', 'mobile', 'user_id')->find($access->job_id);
        $companyUser = Member::select('nickname')->where('id', $job->user_id)->get()->first();

        $data = [
            'company_cn' => $job->company_cn,
            'jobs_name' => $job->jobs_name,
            'mobile' => $job->mobile,
            'nickname' => $companyUser->nickname,
            'username' => $this->member->nickname
        ];
        $data['html'] = response(view('member.interview.item', $data))->getContent();
        echo $this->retJson(0, '成功', $data);
        exit;
    }

    /**
     * 删除用户申请
     * @param $id
     * @return false|string
     */
    public function del($id = 0)
    {
        $access = JobResumeAccess::find($id);
        $access->member_status = 0;
        if ($access->save()) {
            return json_encode(['error' => 0, 'msg' => "成功", 'data' => []]);
        } else {
            return json_encode(['error' => 1, 'msg' => "失败", 'data' => []]);
        }
    }


}